<?php
class ClsNaanalHTML
{
    private $html=null;
    private $dom=null;
    private function __construct($html=null)
    {
        $this->html=$html;
        $this->dom=str_get_html($html);
    }
    public function &getInstance($html=null)
    {
        static $instance=null;
        if(is_null($instance))
        {
            $instance=new ClsNaanalHTML($html);
        }
        return $instance;
    }
    public function &getResources($arrIgnore=false)
    {
        $arrResource=array();
        $arrLink=array();
        $arrObjLink=$this->dom->find("link");
        foreach($arrObjLink as $e)
        {
            if($arrIgnore && in_array($e->href, $arrIgnore)) continue;
            $arrLink[]=$e->href;
        }
        $arrScript=array();
        $arrObjScript=$this->dom->find("script");
        foreach($arrObjScript as $e)
        {
            if($arrIgnore && in_array($e->href, $arrIgnore)) continue;
            $basename=  basename($e->href);
            $arrBasename=explode(".",$basename);
            $arrScript[]=$e->href;
        }
        $arrImage=array();
        $arrObjImage=$this->dom->find("script");
        foreach($arrObjImage as $e)
        {
            if($arrIgnore && in_array($e->src, $arrIgnore)) continue;
            $arrImage[]=$e->src;
        }
        $arrResource["link"]=$arrLink;
        $arrResource["script"]=$arrScript;
        return $arrResource;
    }
    public function save()
    {
        return $this->dom->save();
    }
    public static function generateSelect($name,$arrAttribute,$defaultValue="")
    {
        $select="<select name='{$name}'>
	<!--<option value='text'>text</option>-->";
	if($arrAttribute)
	foreach($arrAttribute as $key=>$value)
	{
		if($key==$defaultValue)
			$select=$select."<option selected='selected' value='".$key."'>".$value."</option>";
		else
			$select=$select."<option value='".$key."'>".$value."</option>";
	}
	$select=$select."</select>";
	return $select;
    }
}
?>